#  1. 打开register.html
#  2. 点击 注册A网页
#  3. 填写 注册A网页 内容
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
url = 'file:///C:/Users/TEACHER/Desktop/NSD2405/html/register.html'
driver.get(url)

sleep(3)
driver.find_element(By.PARTIAL_LINK_TEXT, 'A网页').click()
# 获取当前主窗口的句柄
current = driver.current_window_handle
# 获取所有窗口的句柄，列表
handles = driver.window_handles
# print('主窗口：', current)
# print('所有窗口：', handles)
# 排除不是主窗口，就是新窗口
for item in handles:
    if item != current:
        # print(item)
        # 切换到新打开的窗口
        driver.switch_to.window(item)
        # 获取当前窗口的网址和标题
        print(driver.title, driver.current_url)
        # 输入A网页内容
        driver.find_element(By.ID, 'userA').send_keys('admin')
        driver.find_element(By.ID, 'passwordA').send_keys('123456')
        driver.find_element(By.ID, 'telA').send_keys('18812345678')
        driver.find_element(By.ID, 'emailA').send_keys('123@qq.com')
        sleep(3)
        driver.close()

sleep(3)
driver.quit()